-- 伤害飘字
local HurtFly = class("HurtFly")
local GameUtils = require("utils.GameUtils")
local Color = require("utils.Color")
local AttributeConst = require("const.AttributeConst")

local TIME = 1.2

local HURT_MAP = {
    [AttributeConst.ELEMENT_PHYSICS] = {size = 30, color = Color.newRgb(255, 255, 255)},
    [AttributeConst.ELEMENT_FIRE] = {size = 30, color = Color.newRgb(255, 17, 0)}, -- 火
    [AttributeConst.ELEMENT_WATER] = {size = 30, color = Color.newRgb(0, 255, 255)}, -- 水
    [AttributeConst.ELEMENT_THUNDER] = {size = 30, color = Color.newRgb(228, 0, 255)}, -- 雷
    [AttributeConst.ELEMENT_TREATMENT] = {size = 30, color = Color.newRgb(0, 255, 34)} -- 治疗
}

function HurtFly:create(prompt, parent)
    local object = G_ResourceManager:loadUI("HurtFly")
    local obj, luaEnv = GameUtils.instantiate(object)
    luaEnv:setPrompt(prompt)
    luaEnv:setParent(parent)
    return luaEnv
end

function HurtFly:ctor()
end

function HurtFly:setRect(rect)
    self._rect = rect
end

function HurtFly:setPos(pos)
    self._pos = pos
end

function HurtFly:getPos()
    return self._pos
end

function HurtFly:getRect()
    return self._rect
end

function HurtFly:setPrompt(prompt)
    self._prompt = prompt
end

function HurtFly:setParent(parent)
    self._parent = parent
end

function HurtFly:getParent()
    return self._parent
end

function HurtFly:start()
    GameUtils.destroy(self.gameObject, 1)
end

function HurtFly:setHurtText(params)
    if params.element == AttributeConst.ELEMENT_TREATMENT then
        self._textHurt.text = "+" .. params.value
        self._textHurt.color = Color.getElementColor(params.element)
    else
        if params.absorb and params.value == 0 then
            self._textHurt.text = Lang.get("lang_absorb_hurt")
        else
            self._textHurt.text = "-" .. params.value
        end
        self._textHurt.color = Color.getElementColor(params.element)
    end
    if params.isCrit then
        self._textHurt.fontSize = 26 + 10
    else
        self._textHurt.fontSize = 26
    end
end

function HurtFly:onDestroy()
    self._prompt:onHurtFlyDieNotify(self)
end

return HurtFly
